import os

import ollama

from utils.paths import ROOT_PATH


def ai_chess(chat_history):
    with open(os.path.join(ROOT_PATH, 'utils', 'ai_chess', 'prompt.txt'), 'r', encoding='utf-8') as f:
        system_message = f.read()

    messages = [
        {'role': 'system', 'content': system_message},
        *chat_history
    ]

    response = ollama.chat(
        model='deepseek-r1:14b',
        messages=messages,
        stream=True
    )

    for r in response:
        yield r.message['content']
